from selenium import webdriver
from selenium.webdriver.common.by import By
from time import sleep

driver = webdriver.Chrome()
driver.maximize_window()
sleep(2)
driver.get('https://www.douban.com/')
sleep(3)
# 进入frame框架
f = driver.find_element(By.XPATH, '/html/body/div[2]/div/div[1]/iframe')
driver.switch_to.frame(f)
sleep(3)
# 点击密码登录
driver.find_element(By.CLASS_NAME, 'account-tab-account').click()
sleep(3)
# 输入手机号
driver.find_element(By.ID, 'username').send_keys('15985645480')
sleep(2)
# 输入密码
driver.find_element(By.ID, 'password').send_keys('gW09092434')
sleep(2)
# 点击登录豆瓣
driver.find_element(By.XPATH, '/html/body/div[1]/div[2]/div[1]/div[5]/a').click()
sleep(10)
# 点击短信登录验证
driver.find_element(By.XPATH, '/html/body/div[1]/div[3]/div[1]/div[3]/a').click()
sleep(2)
# 输入手机号
driver.find_element(By.NAME, 'phone').send_keys('15985645480')
# 强制等待20s 输入验证码
sleep(20)
# 点击豆瓣登录
driver.find_element(By.XPATH, '/html/body/div[1]/div[2]/div[1]/div[5]/a').click()
sleep(2)


# 点击同城
driver.find_element(By.XPATH, '//*[@id="db-global-nav"]/div/div[4]/ul/li[5]/a"]').click()
sleep(2)
# 滚动到底部
driver.execute_script('window.scrollTo(0, document.body.scrollHeight)')
sleep(2)
# 点击图片
driver.find_element(By.XPATH, '/html/body/div[4]/div[1]/div/div[1]/div[6]/div[10]/div[2]/ul/li[1]/div[1]/a/img').click()
sleep(2)
# 点击感兴趣
driver.find_element(By.CLASS_NAME, 'collect_btn redbutt').click()
# 对这个活动说两句：
driver.find_element(By.ID, 'interest_comment').send_keys('看标题，感觉不错！')
sleep(2)
# 点击确定
driver.find_element(By.ID, 'save_button').click()

sleep(10)




